﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace project1
{
    class Program
    {
        static void Main(string[] args)
        {
            Rectangle newoblong = new Rectangle(1.1f, Convert.ToSingle(1.2));
            Square newsquare = new Square(Convert.ToSingle(1.1));
            Triangle newdelta = new Triangle(Convert.ToSingle(1.1), Convert.ToSingle(1.2), Convert.ToSingle(1.3));
            if (newoblong.IsLegal()) { Console.WriteLine(newoblong.GetSize()); };
            if (newsquare.IsLegal()) { Console.WriteLine(newsquare.GetSize()); };
            if (newdelta.IsLegal()) { Console.WriteLine(newdelta.GetSize()); };
            Console.ReadKey();
        }

    }

    public interface Shape
    {
        bool IsLegal();
        float GetSize();//首字母大写
    }

    public class Rectangle: Shape//首字母大写
    {
        private float width;
        private float height;

        public Rectangle(float width,float height)
        {
            this.width = width;
            this.height = height;
        }

        public float GetSize()
        {
            return width * height;
        }

        public bool IsLegal()
        {
            return (width > 0 && height > 0);
        }
    }

    public class Square : Shape
    {
        private float side;

        public Square(float side)
        {
            this.side = side;
        }

        public float GetSize()
        {
            return side * side;
        }

        public bool IsLegal()
        {
            return (side > 0);
        }
    }

    public class Triangle : Shape
    {
        private float side1;
        private float side2;
        private float side3;

        public Triangle(float side1,float side2,float side3)
        {
            this.side1 = side1;
            this.side2 = side2;
            this.side3 = side3;
        }

        public float GetSize()
        {

            double p = 0.5 * (this.side1 + this.side2 + this.side3);
            return Convert.ToSingle(Math.Sqrt(p * (p - this.side1) * (p - this.side2) * (p - this.side3)));
        }

        public bool IsLegal()
        {
            return (this.side1 < this.side2 + this.side3 && this.side2 < this.side1 + this.side3 && this.side3 < this.side1 + this.side2);
        }
    }

}
